package com.xuxueli.crawler.test;

import com.xuxueli.crawler.XxlCrawler;
import com.xuxueli.crawler.annotation.PageFieldSelect;
import com.xuxueli.crawler.annotation.PageSelect;
import com.xuxueli.crawler.conf.XxlCrawlerConf;
import com.xuxueli.crawler.parser.PageParser;
import com.xuxueli.crawler.proxy.ProxyMaker;
import com.xuxueli.crawler.proxy.strategy.RoundProxyMaker;
import com.xuxueli.crawler.test.entity.Cart;
import com.xuxueli.crawler.test.entity.Cartdetail;
import com.xuxueli.crawler.test.util.HibernateUtil;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
 *  lcx 爬取所有最大库存
 * */
public class AllcartDetailAsInventory {

    static Map<String, String> paramMap = new HashMap<>();

    //探测 最大物品库存
    @PageSelect(cssQuery = "body")
    public static class InventoryPageVo {


        //是否有错误警告
        @PageFieldSelect(cssQuery = "div.alert", selectType = XxlCrawlerConf.SelectType.HTML)
        private String alert;

        public String getAlert() {
            return alert;
        }

        public void setAlert(String alert) {
            this.alert = alert;
        }

        //拉取需要的的post参数
        @PageFieldSelect(cssQuery = "#addItemToCart > #hitsCfs", selectType = XxlCrawlerConf.SelectType.VAL)
        private String hitsCfs;

        @PageFieldSelect(cssQuery = "#addItemToCart > #hitsCfsMeta", selectType = XxlCrawlerConf.SelectType.VAL)
        private String hitsCfsMeta;

        @PageFieldSelect(cssQuery = "#addItemToCart > #action", selectType = XxlCrawlerConf.SelectType.VAL)
        private String action;

        @PageFieldSelect(cssQuery = "#addItemToCart > #id_unit", selectType = XxlCrawlerConf.SelectType.VAL)
        private String id_unit;

        @PageFieldSelect(cssQuery = "#addItemToCart > #redirect_to", selectType = XxlCrawlerConf.SelectType.VAL)
        private String redirect_to;

        @PageFieldSelect(cssQuery = "#addItemToCart > #id_bundle", selectType = XxlCrawlerConf.SelectType.VAL)
        private String id_bundle;

        //商品的ean信息等
        @PageFieldSelect(cssQuery = "#specs-full dd", selectType = XxlCrawlerConf.SelectType.HTML)
        private List<String> specifications;

        //商品的ean信息名字等 用于找到ean是第几个
        @PageFieldSelect(cssQuery = "#specs-full dt", selectType = XxlCrawlerConf.SelectType.HTML)
        private List<String> specificationNames;

        public List<String> getSpecificationNames() {
            return specificationNames;
        }

        public void setSpecificationNames(List<String> specificationNames) {
            this.specificationNames = specificationNames;
        }

        public List<String> getSpecifications() {
            return specifications;
        }

        public void setSpecifications(List<String> specifications) {
            this.specifications = specifications;
        }

        public String getHitsCfs() {
            return hitsCfs;
        }

        public void setHitsCfs(String hitsCfs) {
            this.hitsCfs = hitsCfs;
        }

        public String getHitsCfsMeta() {
            return hitsCfsMeta;
        }

        public void setHitsCfsMeta(String hitsCfsMeta) {
            this.hitsCfsMeta = hitsCfsMeta;
        }

        public String getAction() {
            return action;
        }

        public void setAction(String action) {
            this.action = action;
        }

        public String getId_unit() {
            return id_unit;
        }

        public void setId_unit(String id_unit) {
            this.id_unit = id_unit;
        }

        public String getRedirect_to() {
            return redirect_to;
        }

        public void setRedirect_to(String redirect_to) {
            this.redirect_to = redirect_to;
        }

        public String getId_bundle() {
            return id_bundle;
        }

        public void setId_bundle(String id_bundle) {
            this.id_bundle = id_bundle;
        }

        @PageFieldSelect(cssQuery = "select.unit-quantity-input", selectType = XxlCrawlerConf.SelectType.HTML)
        private List<String> shopInventoryList;

        //第一层的商品数量
        @PageFieldSelect(cssQuery = ".unit-labels > b > span", selectType = XxlCrawlerConf.SelectType.HTML)
        private String quantityCommodity;

        //第一层的商品名称
        @PageFieldSelect(cssQuery = "h1", selectType = XxlCrawlerConf.SelectType.HTML)
        private String quantityName;

        //第一层商铺名称
        @PageFieldSelect(cssQuery = "a > b", selectType = XxlCrawlerConf.SelectType.HTML)
        private String storeName;

        //第二层商铺名称
        @PageFieldSelect(cssQuery = "dd > small > font > font", selectType = XxlCrawlerConf.SelectType.HTML)
        private List<String> storeName2;

        //第二层的商品数量
        @PageFieldSelect(cssQuery = "[name=\"amount_cart_unit\"]", selectType = XxlCrawlerConf.SelectType.VAL)
        private List<String> quantityCommodity2;

        //第二层的商品名称
        @PageFieldSelect(cssQuery = "a > h6", selectType = XxlCrawlerConf.SelectType.HTML)
        private List<String> quantityName2;

        //第二层的十以下的物品标志
        @PageFieldSelect(cssQuery = "b.txtcolor-alert", selectType = XxlCrawlerConf.SelectType.HTML)
        private List<String> txtAlert;

        //第二层的商品链接
        @PageFieldSelect(cssQuery = ".small-10 > a", selectType = XxlCrawlerConf.SelectType.ATTR, selectVal = "href")
        private List<String> hrefList2;

        public String getStoreName() {
            return storeName;
        }

        public void setStoreName(String storeName) {
            this.storeName = storeName;
        }

        public List<String> getStoreName2() {
            return storeName2;
        }

        public void setStoreName2(List<String> storeName2) {
            this.storeName2 = storeName2;
        }

        public List<String> getHrefList2() {
            return hrefList2;
        }

        public void setHrefList2(List<String> hrefList2) {
            this.hrefList2 = hrefList2;
        }

        public List<String> getTxtAlert() {
            return txtAlert;
        }

        public void setTxtAlert(List<String> txtAlert) {
            this.txtAlert = txtAlert;
        }

        public List<String> getQuantityCommodity2() {
            return quantityCommodity2;
        }

        public void setQuantityCommodity2(List<String> quantityCommodity2) {
            this.quantityCommodity2 = quantityCommodity2;
        }

        public List<String> getQuantityName2() {
            return quantityName2;
        }

        public void setQuantityName2(List<String> quantityName2) {
            this.quantityName2 = quantityName2;
        }

        public String getQuantityName() {
            return quantityName;
        }

        public void setQuantityName(String quantityName) {
            this.quantityName = quantityName;
        }

        public String getQuantityCommodity() {
            return quantityCommodity;
        }

        public void setQuantityCommodity(String quantityCommodity) {
            this.quantityCommodity = quantityCommodity;
        }

        public List<String> getShopInventoryList() {
            return shopInventoryList;
        }

        public void setShopInventoryList(List<String> shopInventoryList) {
            this.shopInventoryList = shopInventoryList;
        }


        //拉取需要的的post参数
        @PageFieldSelect(cssQuery = ".unit-quantity-form > #hitsCfs", selectType = XxlCrawlerConf.SelectType.VAL)
        private List<String> hitsCfsList;

        @PageFieldSelect(cssQuery = ".unit-quantity-form > #hitsCfsMeta", selectType = XxlCrawlerConf.SelectType.VAL)
        private List<String> hitsCfsMetaList;


        @PageFieldSelect(cssQuery = "[name=\"id_unit\"]", selectType = XxlCrawlerConf.SelectType.VAL)
        private List<String> id_unitList;

        @PageFieldSelect(cssQuery = "[name=\"amount_cart_unit\"]", selectType = XxlCrawlerConf.SelectType.VAL)
        private List<String> amount_cart_unitList;

        @PageFieldSelect(cssQuery = "[name=\"amount_cart_unit\"]", selectType = XxlCrawlerConf.SelectType.VAL)
        private List<String> id_warrantyList;

        @PageFieldSelect(cssQuery = "[name=\"amount_cart_unit\"]", selectType = XxlCrawlerConf.SelectType.VAL)
        private List<String> id_bundleList;

        @PageFieldSelect(cssQuery = "[name=\"amount_cart_unit\"]", selectType = XxlCrawlerConf.SelectType.VAL)
        private List<String> promotionsList;


        public List<String> getId_unitList() {
            return id_unitList;
        }

        public void setId_unitList(List<String> id_unitList) {
            this.id_unitList = id_unitList;
        }

        public List<String> getAmount_cart_unitList() {
            return amount_cart_unitList;
        }

        public void setAmount_cart_unitList(List<String> amount_cart_unitList) {
            this.amount_cart_unitList = amount_cart_unitList;
        }

        public List<String> getId_warrantyList() {
            return id_warrantyList;
        }

        public void setId_warrantyList(List<String> id_warrantyList) {
            this.id_warrantyList = id_warrantyList;
        }

        public List<String> getId_bundleList() {
            return id_bundleList;
        }

        public void setId_bundleList(List<String> id_bundleList) {
            this.id_bundleList = id_bundleList;
        }

        public List<String> getPromotionsList() {
            return promotionsList;
        }

        public void setPromotionsList(List<String> promotionsList) {
            this.promotionsList = promotionsList;
        }

        public List<String> getHitsCfsList() {
            return hitsCfsList;
        }

        public void setHitsCfsList(List<String> hitsCfsList) {
            this.hitsCfsList = hitsCfsList;
        }

        public List<String> getHitsCfsMetaList() {
            return hitsCfsMetaList;
        }

        public void setHitsCfsMetaList(List<String> hitsCfsMetaList) {
            this.hitsCfsMetaList = hitsCfsMetaList;
        }


        //删除参数
        @PageFieldSelect(cssQuery = "a.unit-del", selectType = XxlCrawlerConf.SelectType.ATTR, selectVal = "hitscfs")
        private List<String> delHitsCfsList;

        @PageFieldSelect(cssQuery = "a.unit-del", selectType = XxlCrawlerConf.SelectType.ATTR, selectVal = "hitscfsmeta")
        private List<String> delHitsCfsMetaList;
        @PageFieldSelect(cssQuery = "a.unit-del", selectType = XxlCrawlerConf.SelectType.ATTR, selectVal = "data-unit-id")
        private List<String> delId_unitList;

        @PageFieldSelect(cssQuery = "[name=\"amount_cart_unit\"]", selectType = XxlCrawlerConf.SelectType.VAL)
        private List<String> delCountList;

        public List<String> getDelHitsCfsList() {
            return delHitsCfsList;
        }

        public void setDelHitsCfsList(List<String> delHitsCfsList) {
            this.delHitsCfsList = delHitsCfsList;
        }

        public List<String> getDelHitsCfsMetaList() {
            return delHitsCfsMetaList;
        }

        public void setDelHitsCfsMetaList(List<String> delHitsCfsMetaList) {
            this.delHitsCfsMetaList = delHitsCfsMetaList;
        }

        public List<String> getDelId_unitList() {
            return delId_unitList;
        }

        public void setDelId_unitList(List<String> delId_unitList) {
            this.delId_unitList = delId_unitList;
        }

        public List<String> getDelCountList() {
            return delCountList;
        }

        public void setDelCountList(List<String> delCountList) {
            this.delCountList = delCountList;
        }

        @Override
        public String toString() {
            return "InventoryPageVo{" +
                    "hitsCfs='" + hitsCfs + '\'' +
                    ", hitsCfsMeta='" + hitsCfsMeta + '\'' +
                    ", action='" + action + '\'' +
                    ", id_unit='" + id_unit + '\'' +
                    ", redirect_to='" + redirect_to + '\'' +
                    ", id_bundle='" + id_bundle + '\'' +
                    ", shopInventoryList=" + shopInventoryList +
                    '}';
        }
    }

    //通过传入的参数查询属性的位置
    private static int selectPamAsTdName(List<String> nameList, String tdName) {

        int i = 0;
        for (String name : nameList) {
            if (tdName.equals(name)){
                return i;
            }
            i++;
        }
        return 0;
    }


    //查询列表商品个数在十个以下的的商品
    public static void main(String[] args) {


        for (int max = 7; max <= 10000; max++) {

            //查询需要爬取得商品
            final String[] link = new String[2000];

            int j = 0;
            Map<String, String> cookieMap = new HashMap<>();
            final List<Cartdetail> cartdetailList = new ArrayList();
            cookieMap.put("CARTID", "15337095395b6a8ce36557d");
            cookieMap.put("BUYER_CITY_SELECTED", "80");
            cookieMap.put("PHPSESSID", "eetl3p2uhbudek74edqsk4hcrmsb5tei");

            final HibernateUtil hibernateUtil = new HibernateUtil();
            List<Cart> cartList = hibernateUtil.selectAllCartDetailByAllcart();

            for (Cart cart : cartList) {
                j++;
                link[j] = cart.getCartHtrf();
            }
            Map<String, String> headMap = new HashMap<>();

            headMap.put("pragma", "no-cache");
            headMap.put("server", "Apache");
            headMap.put("strict-transport-security", "max-age=0");
            headMap.put("transfer-encoding", "chunked");
            headMap.put("vary", "Accept-Encoding");
            headMap.put("x-content-type-options", "nosniff");
            headMap.put("x-frame-options", "SAMEORIGIN");
            headMap.put("login_failed", "deleted");
            headMap.put("login_source", "deleted");

            //link[0] = "https://saudi.souq.com/sa-en/casio-g-shock-big-case-series-white-black-watch-ga-400-7a-7441455/i/";

            XxlCrawler crawler = new XxlCrawler.Builder()
                    .setUrls(link)
                    .setIfPost(true)
                    .setThreadCount(1).setPauseMillis(2000)
                    .setAllowSpread(false)
                    .setHeaderMap(headMap)
                    //.setProxyMaker(proxyMaker)
                    .setCookieMap(cookieMap)
                    .setPageParser(
                            new PageParser<InventoryPageVo>() {

                                int i = 0;

                                @Override
                                public boolean parse(Document html, Element pageVoElement, InventoryPageVo pageVo) {
                                    // 解析封装 PageVo 对象
                                    System.out.println("---------------------------------------------------------");
                                    String pageUrl = html.baseUri();
                                    System.out.println(pageVo.toString());
                                    System.out.println("---------------------------------------------------------");

                                    //探测当前分类下的最大库存数量
                                    //如果第一页没有价格则添加购物车
                                    if (pageVo.getQuantityCommodity() == null) {
                                        selectCartDetail(pageVo);
                                    } else {
                                        Cartdetail cartdetail = new Cartdetail();
                                        cartdetail.setName(pageVo.getQuantityName());
                                        cartdetail.setKc(pageVo.getQuantityCommodity());
                                        cartdetail.setHref(pageUrl);
                                        cartdetail.setStorename(pageVo.getStoreName());
                                        //cartdetail.setId((long) i++);
                                        cartdetailList.add(cartdetail);

                                    }
                                    return true;
                                }

                            }
                    )
                    .build();

            System.out.println("start");
            crawler.start(true);

            hibernateUtil.save(cartdetailList, max);

            selectCartDetailAsAll(max);

            //hibernateUtil.saveCategory((InventoryPageVo)crawler.getPageVo());
            //selectCartDetail();

            try {
                Thread.sleep(600000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println("end");
        }
    }


    //把商品添加到购物车
    public static void selectCartDetail(InventoryPageVo pageVo) {

        Map<String, String> cookieMap = new HashMap<>();

        Map<String, String> headMap = new HashMap<>();

        Map<String, String> paramMap = new HashMap<>();

        headMap.put("pragma", "no-cache");
        headMap.put("server", "Apache");
        headMap.put("strict-transport-security", "max-age=0");
        headMap.put("transfer-encoding", "chunked");
        headMap.put("vary", "Accept-Encoding");
        headMap.put("x-content-type-options", "nosniff");
        headMap.put("x-frame-options", "SAMEORIGIN");
        headMap.put("login_failed", "deleted");
        headMap.put("login_source", "deleted");

        cookieMap.put("CARTID", "15337095395b6a8ce36557d");
        cookieMap.put("BUYER_CITY_SELECTED", "80");
        cookieMap.put("PHPSESSID", "eetl3p2uhbudek74edqsk4hcrmsb5tei");
      /*  cookieMap.put("PLATEFORMC","ae");
        cookieMap.put("COCODE_AE","ae");
        cookieMap.put("PLATEFORML","en");
        cookieMap.put("UserViews","%2C11679149%2C32158751");
        cookieMap.put("VT_HDR","2");
        cookieMap.put("__gads","ID=b7b2e2eb48de5b4c:T=1533350925:S=ALNI_Mao5Isp6FT6XYMd5v0tr6e5kXZgYg");
        cookieMap.put("_dc_gtm_UA-31806200-1","1");
        cookieMap.put("_ga","GA1.2.1169972056.1533350926");
        cookieMap.put("_ga","GA1.3.1169972056.1533350926");
        cookieMap.put("_gat_UA-31806200-1","1");
        cookieMap.put("_gid","GA1.3.1994490819.1533350926");
        cookieMap.put("_gid","GA1.2.1994490819.1533350926");
        cookieMap.put("ab.storage.sessionId.2e4ae497-9aed-4a69-8a2d-91cd396ab384","%7B%22g%22%3A%22c7d2a320-16c4-10d6-3258-7a3ffc007fc7%22%2C%22e%22%3A1533355273615%2C%22c%22%3A1533344862961%2C%22l%22%3A1533353473615%7D");
        cookieMap.put("abRedirect","1");
        cookieMap.put("c_Ident","15333509236648");
        cookieMap.put("cmgvo","Typed%2FBookmarkedTyped%2FBookmarkedundefined");
        cookieMap.put("cto_lwid","cf823bee-3222-4275-884b-cb780f1476bd");
        cookieMap.put("s_campaign","NA%3ANA%3ANA%3ANA%3ANA%3ANA%3ANA%3ANA%3ANA%3ANA%3ANA%3ANA%3ANA%3ANA%3ANA%3Aae%3Aen%3ABeverages%3ANA%3ADirect%3Afree");
        cookieMap.put("s_cc","true");
        cookieMap.put("s_depth","45");
        cookieMap.put("s_dl","1");
        cookieMap.put("s_ev21","%5B%5B%27Typed%2FBookmarked%27%2C%271533350925648%27%5D%5D");
        cookieMap.put("s_ev22","%5B%5B%27Typed%2FBookmarked%253A%2520UnitPage%27%2C%271533350925649%27%5D%5D");
        cookieMap.put("s_fid","3383C9E55CED24B6-0D3AAE8DAFF7FCFD");
        cookieMap.put("s_nr_lifetime","1533353487832-New");
        cookieMap.put("s_nr_quarter","1533353487832-New");
        cookieMap.put("s_nr_year","1533353487832-New");
        cookieMap.put("s_ppv","UnitPage%2C41%2C41%2C1014%2C1918%2C1014%2C1920%2C1080%2C1%2CP");
        cookieMap.put("s_ppvl","ShoppingCart%2C72%2C72%2C658%2C1918%2C658%2C1920%2C1080%2C1%2CP");
        cookieMap.put("s_shipping_service","undefined");
        cookieMap.put("s_source","%5B%5BB%5D%5D");
        cookieMap.put("s_sq","%5B%5BB%5D%5D");
        cookieMap.put("s_vs","1");
        cookieMap.put("tree_top_nav_ae_ae_en_","1");
        cookieMap.put("tree_top_nav_ae_ae_en_fmcg","1");*/

        /*
        cookieMap.put("s_ppv","ShoppingCart%2C35%2C35%2C359%2C1918%2C359%2C1920%2C1080%2C1%2CP");
        cookieMap.put("s_ppvl","ShoppingCart%2C38%2C32%2C359%2C1918%2C359%2C1920%2C1080%2C1%2CP");
        cookieMap.put("s_ev22","%5B%5B%27Typed%2FBookmarked%253A%2520ShoppingCart%27%2C%271533307554926%27%5D%5D");
        cookieMap.put("c_Ident","15333075519246");*/
        //cookieMap.put("BUYER_CITY_SELECTED","80");

        //cookieMap.put("s_ppvl","ShoppingCart%2C47%2C47%2C452%2C1918%2C452%2C1920%2C1080%2C1%2CP");

        //paramMap.put("hitsCfs", "e4552c90f2cab8ab30e916ace1ac2e42");
        //paramMap.put("hitsCfsMeta", "pM7TlGs3WqRiawaRFFV74OzfrO9PqTCyICoFMi9w98LLFA8msKQShiwF/CN9irsWRx+8Wge2q8H7ziLn2O3mzTYmXHsjn3FhpzD79X/q6nKAYYkkFgAcrG4YHVGlhOfGmUN7K+KjrCsrKeGDamXsbOGeRtLS1sVYoZdkEipJYms=");
        //paramMap.put("action", "add_item_to_cart");
        //paramMap.put("id_unit", "32086000135");
        //paramMap.put("id_warranty", id_warranty);
        //paramMap.put("redirect_to", "/shopping_cart.php");
        //paramMap.put("id_bundle", "0");
        //paramMap.put("id_warranty", "1");
        //paramMap.put("quantity", quantity);


        paramMap.put("hitsCfs", pageVo.getHitsCfs());
        paramMap.put("hitsCfsMeta", pageVo.getHitsCfsMeta());
        paramMap.put("action", "add_item_to_cart");
        paramMap.put("id_unit", pageVo.getId_unit());
        paramMap.put("redirect_to", pageVo.getRedirect_to());
        paramMap.put("id_bundle", "0");
        paramMap.put("id_warranty", "1");
        //paramMap.put("quantity", quantity);*/


        final String[] link = {
                "https://uae.souq.com/ae-en/shopping_cart.php"
        };

        XxlCrawler crawler1 = new XxlCrawler.Builder()
                .setUrls(link)
                .setThreadCount(1).setPauseMillis(1000)
                .setAllowSpread(false)
                .setIfPost(true)
                .setHeaderMap(headMap)
                .setParamMap(paramMap)
                .setCookieMap(cookieMap)
                .setPageParser(
                        new PageParser<InventoryPageVo>() {
                            @Override
                            public boolean parse(Document html, Element pageVoElement, InventoryPageVo pageVo) {
                                // 解析封装 PageVo 对象
                                System.out.println("---------------------------------------------------------");
                                System.out.println(pageVo.toString());
                                System.out.println("----------——-----------------------------------------------");
                                //探测当前分类下的最大分页数量
                                //selectCartDetailAsAll();

                                return true;
                            }

                        }
                )
                .build();

        System.out.println("start");
        crawler1.start(true);
        //selectCartDetailAsAll();
        //selectCartDetail2(pageVo);


        System.out.println("end");
    }

    //获取购物车
    public static void selectCartDetailAsAll(final int max) {


        Map<String, String> cookieMap = new HashMap<>();

        Map<String, String> headMap = new HashMap<>();

        headMap.put("pragma", "no-cache");
        headMap.put("server", "Apache");
        headMap.put("strict-transport-security", "max-age=0");
        headMap.put("transfer-encoding", "chunked");
        headMap.put("vary", "Accept-Encoding");
        headMap.put("x-content-type-options", "nosniff");
        headMap.put("x-frame-options", "SAMEORIGIN");
        headMap.put("login_failed", "deleted");
        headMap.put("login_source", "deleted");

        cookieMap.put("CARTID", "15337095395b6a8ce36557d");
        cookieMap.put("BUYER_CITY_SELECTED", "80");
        cookieMap.put("PHPSESSID", "eetl3p2uhbudek74edqsk4hcrmsb5tei");

        final String[] link = {
                "https://uae.souq.com/ae-en/shopping_cart.php?aoc=f"
        };

        XxlCrawler crawler1 = new XxlCrawler.Builder()
                .setUrls(link)
                .setThreadCount(1).setPauseMillis(1000)
                .setAllowSpread(false)
                .setHeaderMap(headMap)
                .setCookieMap(cookieMap)
                .setPageParser(
                        new PageParser<InventoryPageVo>() {
                            int i = 0;

                            @Override
                            public boolean parse(Document html, Element pageVoElement, InventoryPageVo pageVo) {
                                // 解析封装 PageVo 对象
                                System.out.println("---------------------------------------------------------");
                                System.out.println(pageVo.toString());
                                selectCartDetail2(pageVo,max);
                                System.out.println("----------——-----------------------------------------------");

                                return true;
                            }

                        }
                )
                .build();

        System.out.println("start");
        crawler1.start(true);

        System.out.println("end");
    }


    //拉取最大库存
    public synchronized static void selectCartDetail2(InventoryPageVo pageVo, int max) {

        final List<Cartdetail> cartdetailList = new ArrayList<>();

        for (int j = 0; j < pageVo.getHitsCfsList().size(); j++) {



            Map<String, String> cookieMap = new HashMap<>();
            Map<String, String> headMap = new HashMap<>();
            Map<String, String> paramMap = new HashMap<>();

            headMap.put("pragma", "no-cache");
            headMap.put("server", "Apache");
            headMap.put("strict-transport-security", "max-age=0");
            headMap.put("transfer-encoding", "chunked");
            headMap.put("vary", "Accept-Encoding");
            headMap.put("x-content-type-options", "nosniff");
            headMap.put("x-frame-options", "SAMEORIGIN");
            headMap.put("login_failed", "deleted");
            headMap.put("login_source", "deleted");

            cookieMap.put("CARTID", "15337095395b6a8ce36557d");
            cookieMap.put("BUYER_CITY_SELECTED", "89");
            cookieMap.put("PHPSESSID", "eetl3p2uhbudek74edqsk4hcrmsb5tei");


            paramMap.put("hitsCfs", pageVo.getHitsCfsList().get(j));
            paramMap.put("hitsCfsMeta", pageVo.getHitsCfsMetaList().get(j));
            paramMap.put("action", "update_item_quantity");
            paramMap.put("id_unit", pageVo.getId_unitList().get(j));
            //paramMap.put("id_warranty", id_warranty);
            paramMap.put("id_bundle", "0");
            paramMap.put("id_warranty", "1");
            paramMap.put("quantity", "99");
            paramMap.put("amount_cart_unit", "2");
            paramMap.put("promotions", "0");

            final String[] link = {
                    "https://uae.souq.com/ae-en/shopping_cart.php"
            };

            XxlCrawler crawler2 = new XxlCrawler.Builder()
                    .setUrls(link)
                    .setThreadCount(1).setPauseMillis(1000)
                    .setAllowSpread(false)
                    .setIfPost(true)
                    .setParamMap(paramMap)
                    .setHeaderMap(headMap)
                    .setCookieMap(cookieMap)
                    .setPageParser(
                            new PageParser<InventoryPageVo>() {
                                int i = 0;

                                @Override
                                public boolean parse(Document html, Element pageVoElement, InventoryPageVo pageVo) {
                                    // 解析封装 PageVo 对象
                                    System.out.println("---------------------------------------------------------");
                                    System.out.println(pageVo.getAmount_cart_unitList().size());
                                    System.out.println("---------------------------------------------------------");

                                    //del(pageVo);
                                    return true;
                                }

                            }
                    )
                    .build();

            System.out.println("start");
            crawler2.start(true);

            InventoryPageVo pageVoTem =(InventoryPageVo) crawler2.getPageVo();
            Cartdetail cartdetail = new Cartdetail();
            cartdetail.setName(pageVoTem.getQuantityName2().get(0));
            cartdetail.setKc(pageVoTem.getQuantityCommodity2().get(0));
            cartdetail.setHref(pageVoTem.getHrefList2().get(0));
            cartdetail.setStorename(pageVoTem.getStoreName2().get(0));
            //cartdetail.setId((long) i++);
            //如果商品不满10个则之前已经处理了 这里需要跳过
            if (!"null".equals(pageVoTem.getTxtAlert().get(0))){
                continue;
            }
            cartdetailList.add(cartdetail);
            System.out.println("end");
        }
        HibernateUtil hibernateUtil = new HibernateUtil();
        hibernateUtil.save(cartdetailList, max);
    }


    //删除这个
    public static void del(InventoryPageVo pageVo) {

        Map<String, String> cookieMap = new HashMap<>();
        Map<String, String> headMap = new HashMap<>();
        Map<String, String> paramMap = new HashMap<>();

        headMap.put("pragma", "no-cache");
        headMap.put("server", "Apache");
        headMap.put("strict-transport-security", "max-age=0");
        headMap.put("transfer-encoding", "chunked");
        headMap.put("vary", "Accept-Encoding");
        headMap.put("x-content-type-options", "nosniff");
        headMap.put("x-frame-options", "SAMEORIGIN");
        headMap.put("login_failed", "deleted");
        headMap.put("login_source", "deleted");

        cookieMap.put("CARTID", "15337095395b6a8ce36557d");
        cookieMap.put("BUYER_CITY_SELECTED", "80");
        cookieMap.put("PHPSESSID", "eetl3p2uhbudek74edqsk4hcrmsb5tei");

        paramMap.put("active", "removeUnit");
        paramMap.put("id_unit", pageVo.getDelId_unitList().get(0));
        paramMap.put("count", pageVo.getDelCountList().get(0));
        paramMap.put("action", "yes");
        paramMap.put("id_warranty", "1");
        paramMap.put("promotions", "0");
        paramMap.put("hitsCfs", pageVo.getDelHitsCfsList().get(0));
        paramMap.put("hitsCfsMeta", pageVo.getDelHitsCfsMetaList().get(0));


        final String[] link = {
                "https://uae.souq.com/ae-en/shopping_cart.php"
        };

        XxlCrawler crawler3 = new XxlCrawler.Builder()
                .setUrls(link)
                .setThreadCount(1).setPauseMillis(1000)
                .setAllowSpread(false)
                .setIfPost(true)
                .setHeaderMap(headMap)
                .setParamMap(paramMap)
                .setCookieMap(cookieMap)
                .setPageParser(
                        new PageParser<InventoryPageVo>() {

                            @Override
                            public boolean parse(Document html, Element pageVoElement, InventoryPageVo pageVo) {
                                // 解析封装 PageVo 对象
                                System.out.println("---------------------------------------------------------");
                                System.out.println("---------------------------------------------------------");
                                return true;
                            }

                        }
                )
                .build();

        System.out.println("start");
        crawler3.start(true);

        System.out.println("end");
    }


}
